using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using AspNetForums;
using AspNetForums.Components;
using AspNetForums.Controls;


namespace AspNetForums.Admin
{
	/// <summary>
	/// Summary description for ManageRoles.
	/// </summary>
	public class ManageRoles : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Repeater RoleRepeater;
		protected System.Web.UI.HtmlControls.HtmlForm formManageRole;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if( !Page.IsPostBack )
				DataBindRoles();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

    
		/*******************************************************************
		// DataBindRoles
		//
		/// <summary>
		/// Databinds the roles repeater
		/// </summary>
		//
		********************************************************************/
		public void DataBindRoles() {
			ArrayList roles = Roles.GetRoles();
		
			RoleRepeater.DataSource = roles;
			RoleRepeater.DataBind();
		}
    
		/*******************************************************************
		// CreateNewRole_Click
		//
		/// <summary>
		/// Used to create a new role
		/// </summary>
		//
		********************************************************************/
		public void CreateNewRole_Click(Object sender, EventArgs e) {

			Button b = (Button) sender;
			TextBox name = (TextBox) b.Parent.FindControl("RoleName");
			//TextBox description = (TextBox) b.Parent.FindControl("RoleDescription");

			// Create the role
			//
			Role role = new Role();
			role.Name = name.Text;
			role.Description = "";
        
			Roles.AddRole(role);

			DataBindRoles();
		}
	}
}
